<template>
  <div class="newinfo">
    <h3 class="title">{{msg.title}}</h3>
    <p class="subtitle">
      <span>发表时间：{{msg.add_time}}</span>
      <span>点击次数:{{msg.click}}</span>
    </p>

    <hr />

    <div class="content" v-html="msg.content"></div>
    <comment :artid="msg.id"></comment>
  </div>
</template>

<style lang="less">
</style>

<script>
//导入评论子组件
import comment from "../subcomponents/comment"
export default {
  data() {
    return {
      id: this.$route.params.id,
      msg: {}
    };
  },
  created() {
    this.getnewinfo();
  },
  methods: {
    getnewinfo() {
      this.$axios({
        method: "get",
        url: "http://www.liulongbin.top:3005/api/getnew/" + this.id
      })
        .then(response => {
          if (response.data.status == 0) {
            this.msg = response.data.message[0];
          } else {
              this.showToastTime("数据错误");
          }
        })
        .catch(err => {
          if(err){
              this.showToastTime("服务器错误");
          }
        });
    },
    showToastTime(msg) {
      const toast = this.$createToast({
        time: 1000,
        txt: msg
      });
      toast.show();
    }
  },
  components: {
      "comment":comment
  }
};
</script>